package cn.juque.jdfsystem.disruptor.event;

import cn.juque.common.base.DisruptorBody;
import cn.juque.common.disruptor.IBusinessEventService;
import cn.juque.jdfsystem.disruptor.bo.FileAddBodyBO;
import cn.juque.jdfsystem.task.FileAddTask;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>FileAddDisruptorEventServiceImpl</li>
 * </ul>
 * @date 2023-01-12 23:52:34
 **/
@Service("fileAddDisruptorEventService")
public class FileAddDisruptorEventServiceImpl implements IBusinessEventService {

    public static final String BEAN = "fileAddDisruptorEventService";

    @Resource
    private FileAddTask fileAddTask;

    /**
     * 具体消费者的实现
     *
     * @param disruptorBody 消息体
     */
    @Override
    public void invoke(DisruptorBody disruptorBody) {
        if (disruptorBody instanceof FileAddBodyBO) {
            FileAddBodyBO bodyBO = (FileAddBodyBO) disruptorBody;
            String[] args = {bodyBO.getNodeName(), bodyBO.getFileId()};
            this.fileAddTask.start(args);
        }
    }
}
